<template>
  <div class="ref">
    <form action="/" >
      <van-search placeholder="" v-model="sval" show-action @search="onSearch" @cancel="onCancel" style="position:fixed;top:0vh;left:0vw;width:100vw;z-index:1"/>
    </form>
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh" style="margin-top:8vh;margin-bottom:8vh;" >
      <van-list v-model="loading" :finished="finished" finished-text="已加载全部数据" @load="onLoad">
        <van-cell v-for="item in list" :key="item.id" :value="item.value" @click="toproduct(item.id)">
          <template #title>
            <span>{{ item.title }}</span><br>
            <span style="font-size: 12px;color: #969799;" v-html="item.label"></span>
          </template>
        </van-cell>
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
import Vue from 'vue'
import { Search, List, Cell, PullRefresh, Toast, Tabbar, TabbarItem, Popup } from 'vant'
import qs from 'qs'
Vue.use(Search).use(List).use(Cell).use(PullRefresh).use(Toast).use(Tabbar).use(TabbarItem).use(Popup)
export default {
  name: 'refaccount3',
  data () {
    return {
      sval: '',
      list: [],
      loading: false,
      finished: false,
      isLoading: false,
      startline: 1,
      fieldref: this.$route.params.fieldref,
      relopeid: this.$route.params.relopeid,
      refobject: this.$route.params.bo
    }
  },
  methods: {
    onLoad () {
      let data = {
        'ref_object': this.refobject,
        'ref_inview': 'sname:in:',
        'view_page': this.startline,
        'view_id': this.$route.params.viewid,
        'ref_classname': this.$route.params.classname,
        'ref_params': this.$route.params.params,
        'refaccount3': 'true'
      }
      data.ref_inview = data.ref_inview.replace(':in:', ':in:' + this.sval)
      this.axios({
        method: 'post',
        url: '/api/ref.listnew.do',
        data: qs.stringify(data)
      }).then(res => {
        //console.log(res)
        if (res.data.flag === '1') {
          Toast(res.data.des)
          if (res.data.des && res.data.des.indexOf('登录过期') >= 0) {
            this.loginout()
          }
        } else {
          let rsdata = res.data.jsondata.outdata
          for (let i = 0; i < rsdata.length; i++) {
            this.list.push(rsdata[i])
          }
          if (rsdata == null || rsdata.length === 0) {
            this.loading = false
            this.finished = true
          } else {
            this.startline = this.startline + 1
            this.loading = false
          }
        }
      }).catch(res => {
        this.reserror(res)
      })
    },
    onRefresh () {
      this.list = []
      this.startline = 1
      this.isLoading = false
      this.loading = true
      this.finished = false
      this.onLoad()
    },
    onSearch () {
      this.list = []
      this.startline = 1
      this.onLoad()
    },
    onCancel () {
      this.sval = ''
      this.list = []
      this.startline = 1
      this.onLoad()
    },
    toproduct (account3id) {
      //console.log(this.relopeid)
      //console.log(account3id)
      this.$router.push({ name: 'hzxydlproduct',
        params: {
          account3id: account3id
        }
      })
    }
  }
}
</script>

<style>
.fieldgroup_title {
    text-align: left;
    margin: 0px;
    padding: 35px 15px 15px;
    color: rgba(69,90,100,0.6);
    font-weight: normal;
    font-size: 14px;
}
</style>
